﻿@{
    ViewBag.Title = "ContentItemForm";
    Layout = "~/Views/Shared/_Form.cshtml";
}

<script>
    var keyValue = request('keyValue');
    var type = request('Type');
    $(function () {
        if (type == 1)
            $('#InputType').remove();
        if (type == 0)
            $('#SelectType').remove();

        $("#ValueType").ComboBox({
            description: "==请选择==",
        });
        $("#ValueType").ComboBoxSetValue("1");
        $(".TypeValue").attr("hidden", "hidden");
        $("#ValueType-option li").click(function () {
            if ($("#ValueType").attr("data-value") == "1") {
                $(".TypeValue").attr("hidden", "hidden");
            } else { $(".TypeValue").removeAttr("hidden"); }
        });
        //获取表单
        if (!!keyValue) {
            var rowdata = top.Form.$("#gridTable").jqGridRow()[0];
            $("#form1").SetWebControls(rowdata);
            var val = "";
            if (rowdata.ValueType != "") {
                val = (rowdata.ValueType) == "数值型" ? 0 : 1;
            }
            $("#ValueType").ComboBoxSetValue(val);
            $("#ValueType").attr('disabled', 'disabled');
            if (val == 1) {
                $(".TypeValue").attr("hidden", "hidden");
            } else { $(".TypeValue").removeAttr("hidden"); }
            if (rowdata.IsDefault.substring(10, 11) == "1") $('#IsDefault').prop('checked', true);
            if (rowdata.IsException.substring(10, 11) == "1") $('#IsException').prop('checked', true);
        }
    })

    //保存表单
    function AcceptClick() {
        if (!$('#form1').Validform()) {
            return false;
        }
        var $gridTable = top.frames["ContentForm"].$("#gridTable");
        var postData = $("#form1").GetWebControls("");
        postData["Id"] = newGuid();
        postData["Type"] = (type == "1") ? "选择型" : "录入型";
        
        postData["ValueType"] = $("#ValueType").attr('data-text');
        if (!!keyValue) {
            $gridTable.setRowData(keyValue, postData);
        } else {
            $gridTable.addRowData(($gridTable.jqGrid("getRowData").length + 1), postData);
        }
        dialogMsg("操作成功。", 1);
        dialogClose();
    }
</script>
<div id="SelectType" style="margin-top: 20px; margin-right: 30px;">
    <table class="form">
        <tr>
            <th class="formTitle">选项标识</th>
            <td class="formValue">
                <input id="Flag" type="text" class="form-control" />
            </td>
        </tr>
        <tr>
            <th class="formTitle">文本名称<font face="宋体">*</font></th>
            <td class="formValue">
                <input id="Text" type="text" class="form-control" />
            </td>
        </tr>
        <tr>
            <th class="formTitle">文本值<font face="宋体">*</font></th>
            <td class="formValue">
                <input id="Value" type="text" class="form-control" />
            </td>
        </tr>
        <tr>
            <th class="formTitle">排序<font face="宋体">*</font></th>
            <td class="formValue">
                <input id="Sort" type="text" class="form-control" />
            </td>
        </tr>
        <tr>
            <th class="formTitle">选项<font face="宋体">*</font></th>
            <td class="formValue">
                <div class="checkbox user-select">
                    <label>
                        <input id="IsDefault" type="checkbox" />
                        默认
                    </label>
                    <label>
                        <input id="IsException" type="checkbox" />
                        异常
                    </label>
                </div>
            </td>
        </tr>
        <tr>
            <th class="formTitle">
                说明
            </th>
            <td class="formValue">
                <input id="Description" type="text" class="form-control" />
            </td>
        </tr>
    </table>
</div>
<div id="InputType" style="margin-top: 20px; margin-right: 30px;">
    <table class="form">
        <tr>
            <th class="formTitle">值类型<font face="宋体">*</font></th>
            <td class="formValue">
                <div id="ValueType" type="select" class="ui-select">
                    <ul>
                        <li data-value="1">文本型</li>
                        <li data-value="0">数值型</li>
                    </ul>
                </div>
            </td>
        </tr>
        <tr>
            <th class="formTitle">默认值</th>
            <td class="formValue">
                <input id="DefaultValue" type="text" class="form-control" />
            </td>
        </tr>
        <tr class="TypeValue">
            <th class="formTitle">最小值<font face="宋体">*</font></th>
            <td class="formValue">
                <input id="MinValue" type="text" class="form-control" />
            </td>
        </tr>
        <tr class="TypeValue">
            <th class="formTitle">最大值<font face="宋体">*</font></th>
            <td class="formValue">
                <input id="MaxValue" type="text" class="form-control" />
            </td>
        </tr>
        <tr class="TypeValue">
            <th class="formTitle">异常设置<font face="宋体">*</font></th>
            <td class="formValue">
                <div class="checkbox user-select">
                    <label>
                        <input id="IsException" type="checkbox" />
                        <font face="宋体">(是-表示范围外异常 否-表示范围内异常)</font>
                    </label>
                </div>
            </td>
        </tr>
        <tr>
            <th class="formTitle">
                说明
            </th>
            <td class="formValue">
                <input id="Description" type="text" class="form-control" />
            </td>
        </tr>
    </table>
</div>
